<?php

/**
 * Framework_Util_LdapAuthenticator
 *
 *
 * @author Application Support Group
 * @copyright University of Georgia
 * @package BAMF
*/
class Framework_Util_LdapAuthenticator extends Framework_Util_Authenticator {

	protected $_ldapConnection;



	/**
	 * __construct()
	 *
	 * @param string $aURL The URL of the LDAP server
	 * @param string $aDN Some base LDAP division references, such as organization and organizational unit
	 *
	 * @package BAMF
	 *
	 */
	public function __construct( $aURL=null, $aDN=null ) {
		parent::__construct( null );
		$this->_ldapConnection = new Framework_Util_LdapConnection($aURL, $aDN);
	}



	/**
	 * authenticate()
	 *
	 * @param string  $aUsername
	 * @param string  $aPassword
	 * @param array   $returnAttributes
	 * @param boolean $returnAll
	 *
	 * @return mixed Array of attributes on success, PEAR Error on failure.
	 *
	 * @package BAMF
	 * 
	 */
	public function authenticate( $aUsername, $aPassword, $returnAttributes = array(), $returnAll = FALSE ) {
		$_output = $this->_ldapConnection->connect( $aUsername, $aPassword );
		if ( !Framework_ErrorHandler::isError( $_output )) {
			$result = $this->_ldapConnection->search( "cn=".$aUsername, $returnAttributes, $returnAll );
			$_output = $result[0];
		}
		return $_output;
	}// end authenticate()



	public function __destruct() {
		parent::__destruct();
	}
}

?>
